layui.use(['table', 'admin', 'ax','element','form'], function () {
    var $ = layui.$;
    var table = layui.table;
    var form = layui.form;
    var $ax = layui.ax;
    var admin = layui.admin;
	var element = layui.element
	
	//tab切换
	element.on('tab(doTabBrief)',function(data){
		console.log(data.index)
	})
	
    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/orderTransportDispatch/detailBydispatchNumber?dispatchNumber=" + Feng.getUrlParam("dispatchNumber"));
    var result = ajax.start();
    form.val('tDispatchForm', result.data);

    /**
     * 调度单表管理
     */
    var TransportDispatch = {
        tableId: "transportDispatchTable"
    };

    /**
     * 初始化表格的列
     */
    TransportDispatch.initColumn = function () {
        return [[
            {field: 'transportNumber', sort: true, title: '货运订单号',templet: '#transportNumberTpl'},
            {field: 'customerOrder', sort: true, title: '客户单号'},
            {field: 'setMentiontime', sort: true, title: '发货日期'},
            {field: 'undertime', sort: true, title: '下单日期'},
            {field: 'lineName', sort: true, title: '线路'},
            {field: 'getUnit', sort: true, title: '收货单位'},
            {field: 'getLocation', sort: true, title: '收货地址'},
            {field: 'getPeople', sort: true, title: '收货人'},
            {field: 'getTel', sort: true, title: '电话'},
            {field: 'goodsName', sort: true, title: '商品名称', totalRowText: '合计：'},
            {field: 'goodsNumber', sort: true, title: '编号'},
            {field: 'goodsNo', sort: true, title: '货号'},
            {field: 'transportMoneyD', sort: true, title: '金额', totalRow: true},
            {field: 'transportPutvolume', sort: true, title: '体积', totalRow: true},
            {field: 'num', sort: true, title: '数量', totalRow: true},
            {field: 'transportMoney', sort: true, title: '配置金额', totalRow: true},
            {field: 'tooDeployVolume', sort: true, title: '配置体积', totalRow: true},
            {field: 'tooDeployNum', sort: true, title: '配置数', totalRow: true},
            {field: 'xianggui', title: '箱规'},
            {field: 'xianggui', sort: true, title: '换算', totalRow: true,
            	templet: function(d){
					if(d.xianggui != '' && d.xianggui != null){
						return (d.tooDeployNum/d.xianggui).toFixed(2)
					} else {
						return ""
					}
            	}
			},
        ]];
    };


    // 渲染表格
    var tableResult = table.render({
        elem: '#' + TransportDispatch.tableId,
        url: Feng.ctxPath + '/orderTransportDispatch/listOrder2?dispatchNumber='+Feng.getUrlParam("dispatchNumber"),
        page: false,
        limit: 1000,
        height: "full-60",
        totalRow: true,
        toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
        cellMinWidth: 100,
        cols: TransportDispatch.initColumn()
    });

    // 工具条点击事件
    table.on('tool(' + TransportDispatch.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'tooDetailed') {
            layer.open({
                type: 2,
                title: '货运订单信息',
                area: ['1200px', '550px'],
                anim: 5,
                content: Feng.ctxPath + '/tDispatch/tooOrderDetailed?transportNumber=' + data.transportNumber,
            });
        }
    });



});
